package server.qiang.Process;

import java.sql.SQLException;

import server.qiang.database.IpMap;
import server.qiang.database.IpObject;
import server.qiang.database.database;
import common.harvin.potocol.Command;
import common.harvin.potocol.Request;
import common.harvin.potocol.Response;

public class P2PConnect {

	private Request request;
	private IpMap ipmap;
	private IpObject ipobject;

	public Response p2pconnect(Request request, IpMap ipmap) {
		this.request = request;
		this.ipmap = ipmap;



		

		Response response = new Response();
		response.setFor_command(Command.P2P_CONNECT);
		response.setSend_Date(request.getSend_Date());

		try {
			
				ipobject = ipmap.getById(request.getSender());
				if (ipobject != null) {
					System.out.println(ipobject.getIp());
					System.out.println(ipobject.getPort());

					response.addData("ip", ipobject.getIp());
					response.addData("port", String.valueOf(ipobject.getPort()));

					System.out.println("p2p connecting");
					
				} else {
					System.out.println("对方没有上传ip");
					response.addData("response", "对方没有上传ip");
				}
			

		} catch (Exception e) {

		}


		return response;
	}
}
